<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="/taglibs.jsp"%>
<!doctype html>
<html>
<head>

    <meta charset="UTF-8">  
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link href="${ctx}/resources/semanticui/semantic.min.css" rel="stylesheet" type="text/css" />
    <link href="${ctx}/resources/apps.css" rel="stylesheet" type="text/css" />
    <title>面试状态</title>
    
</head>
<body>
<div class="ui segment" id="n-page">
&nbsp;<br>
<!-- 所在城市  现任职位   工作状态+电话（电话一栏用***表示，包括自荐，猎头推荐及系统匹配）+推荐人&nbsp;<br/> -->
    <c:choose>
    <c:when test="${recommend.status == 0 || recommend.status == 6}">
        候选人：***&nbsp;<br>&nbsp;<br>
    </c:when>
    <c:otherwise>
        候选人：${person.name}&nbsp;<br>&nbsp;<br>
    </c:otherwise>
</c:choose>
<%--  年龄：<b>${person.age}</b>&nbsp;<br>&nbsp;<br> --%>
所在城市：
	<c:choose>
        <c:when test="${person.cityId == 0 }">
            ${person.cityName}
        </c:when>
        <c:otherwise>
            ${city.name}
        </c:otherwise>
    </c:choose>
    &nbsp;<br>&nbsp;<br>
 现任公司：
	<c:choose>
        <c:when test="${person.companyId == 0 }">
            ${person.companyName}
        </c:when>
        <c:otherwise>
            ${company.name}
        </c:otherwise>
    </c:choose>
    &nbsp;<br>&nbsp;<br>
        现任职位：<b>${person.roleName}</b>&nbsp;<br>&nbsp;<br>
       个人工作年限：<b>${person.workage}</b>年&nbsp;<br>&nbsp;<br>
<c:choose>
    <c:when test="${recommend.status != 0 && recommend.status != 6}">
    电话：<b>${person.phone}</b>&nbsp;<br>
                 
        <c:if test="${recommend.resid != null}">
      	  候选人简历：
      		<a target="_blank" href="https://tiaonali.com/${(recommend.resid).substring(0,(recommend.resid).lastIndexOf('.'))}.html">${recommend.resid}</a>
       		<br>
        </c:if>
<%-- 	<c:if test="${recommend.audioid != null}">
        候选人自我介绍：
        <button class="icon-audio" id="playerBtn" style="margin:0 5px;cursor:pointer;"  playerurl="${ctx}/rs/audio/${recommend.audioid}.amr">播放</button>  
		<div style="width:1px;height:1px;" id="playerQT">  
		  
		 </div> 
   
        <br>
    </c:if> --%>
        
        <br>&nbsp;<br>
    </c:when>
    <c:otherwise>
    	电话：<b>********</b>&nbsp;<br>&nbsp;
    </c:otherwise>
</c:choose>

推荐人：<%-- ${createPerson} --%>
<c:choose>
<c:when test="${recommend.personId == recommend.createby}">
	自荐
</c:when>
<c:when test="${recommend.personId != recommend.createby}">
	他荐
</c:when>
<c:otherwise>
	系统推荐
</c:otherwise>
</c:choose>
&nbsp;<br>&nbsp;<br>
	<c:choose>
    <c:when test="${recommend.status > 0 }">
    <h3 class="ui attached header" id="list-title">
        面试反馈历史记录
    </h3>
    &nbsp;<br>
    <div class="ui attached segment" id="list-items">

    <c:forEach items="${interviews}" var="iv">
        <div class="ui segment listitem">
            日期： ${iv.createTime}<br>类型：
            <c:choose>
                <c:when test="${(iv.itype ==1)}">
                    电话面试
                </c:when> 
             <c:when test="${(iv.itype ==2)}">
                    公司面试
                </c:when> 
                <%--    <c:when test="${(iv.itype ==3)}">
                    笔试
                </c:when>  --%>
                <c:when test="${(iv.itype ==4)}">
                    业务面试
                </c:when> 
                <c:when test="${(iv.itype ==5)}">
                    人事面试
                </c:when>  
                <c:when test="${(iv.itype ==6)}">
                    公司终面
                </c:when>
                <c:when test="${(iv.itype ==7)}">
                    谈薪资
                </c:when>
                <c:otherwise>
                   其他
                </c:otherwise>
            </c:choose>    
            <br>结果：
            <c:choose>
                <c:when test="${(iv.status ==1)}">
                    已发面试邀请
                </c:when> 
                <c:when test="${(iv.status ==2)}">
                    建议继续面试
                </c:when> 
                <c:when test="${(iv.status ==3)}">
                    拒绝
                </c:when> 
                <c:when test="${(iv.status ==4)}">
                    录用
                </c:when> 
                <c:when test="${(iv.status ==6)}">
                   未录用
                </c:when> 
                <c:when test="${(iv.status ==7)}">
                    候选人拒绝
                </c:when> 
                 <c:when test="${(iv.status ==8)}">
                    候选人不合格
                </c:when> 
                <c:when test="${(iv.status ==9)}">
                    薪资没谈拢
                </c:when> 
                <c:when test="${(iv.status ==10)}">
                    入职
                </c:when> 
                <c:when test="${(iv.status ==11)}">
                    未入职
                </c:when> 
                <c:otherwise>
                    奖金已发放
                </c:otherwise>
            </c:choose>    
            <br> 
            	反馈：${iv.remark}
        </div>
    </c:forEach>
        
    </div>
        <h3 class="ui attached header" id="list-title2" style="margin-top: 20px;">
            面试反馈记录
        </h3>
        <div class="ui attached segment" id="list-items2">
            <form class="ui form" id="feedBackForm">
                <div class="field">
                    <label>选择日期</label>
                    <div class="ui input">
                        <input type="date" name="updatedate" id="updatedate" value="${todayStr}">
                    </div>
                </div>
                <div class="field">
                    <label>面试类型</label>
                    <select class="ui selection dropdown" id="itype" name="itype">
                        <option value="1">电话面试</option>
                        <option value="2">公司面试</option>
                        <!-- <option value="3">笔试</option> -->
                        <option value="4">业务面试</option>
                        <option value="5">人事面试</option>
                        <option value="6">公司终面</option>
                        <option value="7">谈薪资</option>
                    </select>
                </div>
                <div class="field">
                    <label>面试结果</label>
                    <select class="ui selection dropdown" id="status" name="status">
                        <!--<option value="1">已发面试邀请</option>-->
                        <option value="2">建议继续面试</option>
                        <option value="3">拒绝</option>
                        <option value="4">录用</option>
                        <option value="6">未录用</option>
                        <option value="7">候选人拒绝</option>
                        <option value="8">候选人不合格</option>
                        <option value="9">薪资没谈拢</option>
                        <option value="10">入职</option>
                        <option value="11">未入职</option>
                        <!--
                        <option value="5">奖金已发放</option>
                        -->
                    </select>
                </div>
                <div class="field">
                    <label>反馈</label>
                    <div class="ui input">
                        <input type="text" name="remark" id="remark" placeholder="请输入反馈信息（必填项）" value="" >
                    </div>
                </div>
                <div class="ui segment" id="btn-next2">
                    <div class="fluid ui button submitBtn" id="next">提交结果</div>
                </div>
            </form>
        </div>
    <br>
        <c:choose>
            <c:when test="${recommend.status > 0 }">
                <h3 class="ui attached header" id="list-title2" style="margin-top: 30px;">
                    面试安排
                </h3>
                <div class="ui attached segment" id="list-items3">
                    <form class="ui form">
                        <div class="field">
                            <label>面试进展</label>
                            <div class="ui input">
                                <select name="round" id="round">
                                    <option value="1">1面</option>
                                    <option value="2">2面</option>
                                    <option value="3">3面</option>
                                    <option value="4">4面</option>
                                    <option value="5">5面</option>
                                    <option value="6">终面</option>
                                </select>
                            </div>
                        </div>
                        <div class="field">
                            <label>面试时间</label>
                            <div class="ui input">
                                <input type="date" name="interviewDate" id="interviewDate" style="width:45%;" placeholder="请选择面试时间" value="${interview.interviewDate}">
                                <span id="sel_start" style="display:flex;">
						   <input type="hidden" id="sel_s_hour" value="${s_hour}"/>
						   <select name="s_hour" id="s_hour">

						        <option value="08" selected>08</option>
						        <option value="09">09</option>
						        <option value="10">10</option>
						        <option value="11">11</option>
						        <option value="12">12</option>
						        <option value="13">13</option>
						        <option value="14">14</option>
						        <option value="15">15</option>
						        <option value="16">16</option>
						        <option value="17">17</option>
						        <option value="18">18</option>
						        <option value="19">19</option>
						        <option value="20">20</option>
                                <option value="21">21</option>
                                <option value="22">22</option>
                                <option value="23">23</option>
						    </select>
						    <select name="s_minute" id="s_minute">
						    	<option value="00" selected>00</option>
						        <option value="10">10</option>
						        <option value="20">20</option>
						        <option value="30">30</option>
						        <option value="40">40</option>
						        <option value="50">50</option>
						    </select>
						    </span>
                            </div>
                        </div>
                        <div class="field">
                            <label>面试地点</label>
                            <div class="ui input">
                                <input type="text" name="interviewSite" id="interviewSite" placeholder="请输入面试地点" value="${interview.interviewSite}">
                            </div>
                        </div>
                        <div class="field">
                            <label>面试官信息</label>
                            <div class="ui input">
                                <input type="text" name="interviewer" id="interviewer" placeholder="请输入面试官信息" value="${interview.interviewer}">
                            </div>
                        </div>
                        <div class="field">
                            <label>面试官联系方式</label>
                            <div class="ui input">
                                <input type="text" name="interviewContact" id="interviewContact" placeholder="请输入面试官联系方式" value="${interview.interviewContact}">
                            </div>
                        </div>
                        <div class="ui center aligned segment" id="choice-buttons">
                            <!--   <div class="two ui buttons">  -->
                            <!--    <div class="ui button active dog" id="bonus">发放奖金</div>  -->
                            <div class="fluid ui button" id="ask">面试邀请</div>
                            <!--  </div> -->
                        </div>
                    </form>
                </div>
            </c:when>
        </c:choose>



	</c:when>
        <c:otherwise>
            <div class="ui segment" id="cont-next">
                <div class="fluid ui button send" id="send">发送职位沟通邀请</div>
            </div>
        </c:otherwise>
	</c:choose>
	

    <input type="hidden" name="recommendstatus" id="recommendstatus" value="${recommend.status}" />

</div>
<script src="${ctx}/resources/jweixin-1.0.0.js"></script>
<script src="${ctx}/resources/semanticui/jquery-2.1.4.min.js"></script>
<script src="${ctx}/resources/semanticui/semantic.js" type="text/javascript"></script>
<script type="text/javascript">

wx.config({
    debug: false, 
    appId: "${config.appid}",  
    timestamp: ${config.currenttimestamp},  
    nonceStr: "${config.nonceStr}", 
    signature: "${config.signatureStr}", 
    jsApiList: ['checkJsApi',
        'onMenuShareTimeline',
        'onMenuShareAppMessage',
        'onMenuShareQQ',
        'onMenuShareWeibo',
        'hideOptionMenu']  
});

    var datasource = { 
        // appenddata:function(data) {
        //     var divstring  = '';
        //     divstring += '<div class="ui segment listitem">';
        //     divstring += '日期： ';
        //     divstring += data.updateTime;
        //     divstring += '<br>';
        //     divstring += '类型：';
        //     if(data.itype == 1) {
        //         divstring += '电话面试';
        //     }
        //     else if(data.itype == 2) {
        //         divstring += '公司面试';
        //     }
        //   /*   else if(data.itype == 3) {
        //         divstring += '笔试';
        //     }  */
        //     else if(data.itype == 4) {
        //         divstring += '业务面试';
        //     } else if(data.itype == 5) {
        //         divstring += '人事面试';
        //     } else if(data.itype == 6) {
        //         divstring += '公司终面';
        //     } else{
        //         divstring += '谈薪资';
        //     }
        //     divstring += '<br>';
        //     divstring += '结果：';
        //     if(data.status == 1) {
        //         divstring += '已发面试邀请';
        //     } else if(data.status == 2) {
        //         divstring += '建议继续面试';
        //     } else if(data.status == 3) {
        //         divstring += '拒绝';
        //     } else if(data.status == 4) {
        //         divstring += '录用';
        //     } else if(data.status == 6) {
        //         divstring += '未录用';
        //     } else if(data.status == 7) {
        //         divstring += '候选人拒绝';
        //     } else if(data.status == 8) {
        //         divstring += '候选人不合格';
        //     } else if(data.status == 9) {
        //         divstring += '薪资没谈拢';
        //     } else if(data.status == 10) {
        //         divstring += '入职';
        //     } else if(data.status == 11) {
        //         divstring += '未入职';
        //     }else {
        //         divstring += '奖金已发放';
        //     }
        //     divstring += '<br> 反馈：';
        //     divstring += data.remark;
        //     var newdata = $(divstring);
        //     $('#list-items').append(newdata);
        // },

        postdatare:function(postdata) {
            var postUrl = '${ctx}/wechat/hunter/hr/creatInterview.do?recommendid=' + ${recommend.id};
            alert(postUrl);

            $.ajax({
                url: postUrl,
                type: "POST",
                data: postdata,
                success:function(data, status) {
                    if(data.errorcode == 0 ) {
                        alert("操作成功");
                        var getUrl = '${ctx}/wechat/hunter/toInterview.do?recommendid='+${recommend.id};
                        location.href = getUrl
                    }   else {
                        alert(data.msg);
                    }
                },
                // error: function() {
                //     alert("服务出错，请稍后尝试");
                // }
            });
        },

        askpostData:function(postdata) {
            var postUrl = '${ctx}/wechat/hunter/hr/updateInterviewStatus.do?action=ask&recommendid='+ ${recommend.id};
            var that = this;

            $.ajax({
                url: postUrl,
                type: "POST",
                data: postdata,
                success:function(data, status) {
                    if(data.errorcode == 0 ) {
                        // that.appenddata(postdata);
                        alert("面试创建成功,候选人将收到您此次的面试邀请通知。")
                        var getUrl = '${ctx}/wechat/hunter/hr/toInterview.do?recommendid='+${recommend.id};
                        location.href = getUrl
                    } else {
                        alert(data.msg);
                    }
                },
                // error: function() {
                //     alert("服务出错，请稍后尝试");
                // }
            });
        },
        
        
        bonuspostData:function(postdata) {
            var postUrl ='${ctx}/wechat/hunter/hr/updateInterviewStatus.do?action=bonus&recommendid=' + ${recommend.id};
            var that = this;

            $.ajax({
                url: postUrl,
                type: "POST",
                data: postdata,
                success:function(data, status) {
                    if(data.errorcode == 0 || data.errorcode == 2) {
                        // that.appenddata(data.data);
                        alert("操作成功");
                        var getUrl = '${ctx}/wechat/hunter/hr/toInterview.do?recommendid='+${recommend.id};
                        location.href = getUrl
                    } else {
                        alert(data.msg);
                    }
                },
                error: function() {
                    alert("服务出错，请稍后尝试");
                }
            });
        } 
    };

    var handler = {      
        activate: function() { 
            $(this).addClass('active').siblings().removeClass('active');           
            // if($(this).attr('id') == 'next') {
            //
            //     var postData = {};
            //
            //     var status = $("#status").val();
            //     var updatedate = $("#updatedate").val();
            //     var itype = $("#itype").val();
            //     var remark = $("#remark").val();
            //
            //     postData['status'] = status;
            //     postData['updateTime'] = updatedate;
            //     postData['itype'] = itype;
            //     postData['remark'] = remark;
            //
            //     datasource.postdatare(postData);
            //
            // }
            // if($(this).attr('id') == 'bonus') {
            // 	var postData = {};
            //     datasource.bonuspostData(postData);
            // }


            if($(this).attr('id') == 'ask') {
                var time = new Date($("#interviewDate").val());
                if (time.getTime()< new Date().getTime()) {
                    alert("面试时间应设置在当天之后！")
                }

            	var postData = {};
            	var interviewDate = $("#interviewDate").val()+" "+$("#s_hour").val()+":"+$("#s_minute").val();

                var interviewSite = $("#interviewSite").val();
                var interviewer = $("#interviewer").val();
                var interviewContact = $("#interviewContact").val();
                var round = $("#round").val();

                postData['interviewDate'] = interviewDate;
                postData['interviewSite'] = interviewSite;
                postData['interviewer'] = interviewer;
                postData['interviewContact'] = interviewContact;
                postData['round'] = round;
                datasource.askpostData(postData);
            }
        } 
    };
    
    function submitFeedBack(postdata){    	 
	     /*  var remark = $("#remark").val();
	      if(!remark || remark =="") {
	         alert("反馈是必填项");
	         return false;
	       } */

         var postUrl = '${ctx}/wechat/hunter/hr/creatInterview.do?recommendid=' + ${recommend.id};
         var that = this;

         $.ajax({
             url: postUrl,
             type: "POST",
             data: postdata,
             success:function(data, status) {
                 
            	 if(data.errorcode == 0 ) {
            		 // datasource.appenddata(postdata);
            		 // $("#status").val();
                     // $("#updatedate").val();
                     // $("#itype").val();
                     // $("#remark").val();
                     alert("操作成功")
                     var getUrl = '${ctx}/wechat/hunter/hr/toInterview.do?recommendid='+${recommend.id};
                     location.href = getUrl

                 } else {
                     alert(data.msg);
                 }
            	 
             },
         });
    }

    function sendAsk() {
        var getUrl = '${ctx}/wechat/hunter/hr/updateRecomStatus.do?jobId='+${recommend.jobId}+'&recommendId='+${recommend.id}+'&empId='+${recommend.personId}+'&status='+6;
        console.log(getUrl);
        $.ajax({
            url: getUrl,
            type: "GET",
            success: function(data,status) {
                if(data.errorcode==1){
                    alert("已发送沟通邀请，等待候选人回复！")
                    var getUrl = '${ctx}/wechat/hunter/hr/toJobView.do?jobid='+${recommend.jobId};
                    location.href = getUrl;
                }
            }
        });
    }

    $(document).ready(function() {
        $("#send").click(function() {
            sendAsk();
        });

           $(".submitBtn").click(function(){
        	   //提交表单
        	   var postData = {};

               var status = $("#status").val();
               var updatedate = $("#updatedate").val();
               var itype = $("#itype").val();
               var remark = $("#remark").val();

               postData['status'] = status;
               postData['updateTime'] = updatedate;
               postData['itype'] = itype;
               postData['remark'] = remark;

               submitFeedBack(postData);
           });
           //面试邀请
             $("#ask").click(function(){
              var date=$("#interviewDate").val();
              var interviewDate =date+" "+$("#s_hour").val()+":"+$("#s_minute").val();
              var interviewSite = $("#interviewSite").val();
              var interviewContact = $("#interviewContact").val();
              var interviewer = $("#interviewer").val();
              var round = $("#round").val();
              if(!date || date ==""){
            	  alert("请选择面试时间");
        	      return false;
              }
       	      if(!interviewSite || interviewSite =="") {
       	         alert("请输入面试地点");
       	         return false;
       	      } 
       	   	  if(!interviewer || interviewer =="") {
     	         alert("请输入面试联系人信息");
     	         return false;
     	      } 
	       	  if(!interviewContact || interviewContact =="") {
	   	         alert("请输入面试联系人电话");
	   	         return false;
	   	      } 
        	   //提交表单
        	   var postData = {};
           	   console.log(interviewDate);
               postData['interviewDate'] = interviewDate;
               postData['interviewSite'] = interviewSite;
               postData['interviewer'] = interviewer;
               postData['interviewContact'] = interviewContact;
               postData['round'] = round;
               datasource.askpostData(postData);
           });

           //发放奖金
           $("#bonus").click(function(){
        	   var postData = {};
               datasource.bonuspostData(postData);
           });
           
           $('.dropdown').dropdown({
               fullTextSearch:true,
           });

           var recommendstatus = $('#recommendstatus').val();
           if(recommendstatus == 0) {
               $('#next').addClass('disabled');
               $('#bonus').addClass('disabled');
           }else if(recommendstatus == 2){
                $('#bonus').addClass('disabled');
           }else if(recommendstatus == 6||
        		   recommendstatus == 8||
        		   recommendstatus == 9||recommendstatus == 11){
           	 // $('#next').addClass('disabled');//提交结果
             $('#bonus').addClass('disabled');//发放奖金
             $('#ask').addClass('disabled');//面试邀请--upd by adela 2019/12/24 @pony提出主动应聘的候选人，点击后加载页面均为有面试反馈的页面，且面试反馈记录、面试安排信息填写完成均可提交
           }else if(recommendstatus == 10){
           	 // $('#next').addClass('disabled');
             $('#ask').addClass('disabled');
           }else if(recommendstatus == 1||recommendstatus == 4||recommendstatus == 7){
        	 $('#bonus').addClass('disabled');//发放奖金
              /* $('#ask').addClass('disabled');//面试邀请 */
           }
           
          /*  $("#ask").click(function(){
             $("#list-items3").toggle();
           }); */
           
           var playerQT = document.getElementById("playerQT");  
           $("#playerBtn").bind("click",function(e){  
               var playerUrl = e.target.getAttribute("playerUrl");  
               playerAudio(playerUrl);  
           });  
           function playerAudio(url){  
               var html ="<audio class='icon-audio' id='player' style='margin:0 5px;cursor:pointer;' src='"+url+"' autoplay preload loop controls>播放</audio >";
               playerQT.innerHTML = html;  
           }
            
           wx.ready(function() {
        	   // document.getElementById('player').play();
           		//wx.hideOptionMenu();
           });
    });
    
    
</script>
</body>
</html>